package com.eightbears.beboy.base.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.eightbears.beboy.R;

/**
 * Created by Bao on 2017/5/4.
 */

public class ShopInfoView extends LinearLayout {

    private LinearLayout ll_name, ll_address, ll_phone, ll_price, ll_date;
    private TextView tv_shop_name, tv_shop_address, tv_shop_phone, tv_shop_price, tv_shop_date;

    private OnItemClickListener mOnItemClickListener;

    public ShopInfoView(Context context) {
        this(context, null);
    }

    public ShopInfoView(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.view_shop_info, this, true);
        ll_name = (LinearLayout) findViewById(R.id.ll_name);
        ll_address = (LinearLayout) findViewById(R.id.ll_address);
        ll_phone = (LinearLayout) findViewById(R.id.ll_phone);
        ll_price = (LinearLayout) findViewById(R.id.ll_price);
        ll_date = (LinearLayout) findViewById(R.id.ll_date);
        tv_shop_name = (TextView) findViewById(R.id.tv_shop_name);
        tv_shop_address = (TextView) findViewById(R.id.tv_shop_address);
        tv_shop_phone = (TextView) findViewById(R.id.tv_shop_phone);
        tv_shop_price = (TextView) findViewById(R.id.tv_shop_price);
        tv_shop_date = (TextView) findViewById(R.id.tv_shop_date);

        ll_phone.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onImageClick(v);
            }
        });
        ll_address.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onImageClick(v);
            }
        });
    }

    public void setShopName(String name){
        if(!TextUtils.isEmpty(name)){
            ll_name.setVisibility(VISIBLE);
            tv_shop_name.setText(name);
        }

    }

    public void setShopAddress(String address){
        if(!TextUtils.isEmpty(address)) {
            ll_address.setVisibility(VISIBLE);
            tv_shop_address.setText(address);
        }
    }

    public void setShopPhone(String phone){
        if(!TextUtils.isEmpty(phone)) {
            ll_phone.setVisibility(VISIBLE);
            tv_shop_phone.setText(phone);
        }
    }

    public void setShopPrice(String price){
        if(!TextUtils.isEmpty(price)) {
            ll_price.setVisibility(VISIBLE);
            tv_shop_price.setText("¥ " + price);
        }
    }

    public void setShopDate(String date){
        if(!TextUtils.isEmpty(date)) {
            ll_date.setVisibility(VISIBLE);
            tv_shop_date.setText(date);
        }
    }

    public void setOnItemClickLinester(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onImageClick(View v);
    }
}
